package com.caseProcess.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.caseProcess.entity.*;
import com.caseProcess.service.CaseCountService;
import com.caseProcess.service.CaseService;
import com.caseProcess.service.PageService;
import com.caseProcess.utils.TimeUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/caseCount")
public class CaseCountController {

    @Resource
    private CaseCountService caseCountService;


    /**
     * 查询统计
     * @param departmentId 部门id 为空或者0代表查询全部
     * @param dateType 时间类型 1 最近一个月 2 最近三个月 3最近半年 4最近1年
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return Result.data{
     * caseEndCount 当前时间段内部门办结的警情
     * caseNoEndCount 当前时间段内部门被分配但是未办结的警情
     * caseAllCount 当前时间段内部门被分配的所有警情
     * }
     */
    @RequestMapping("/getCaseCountEnd")
    public Result getCaseCountEnd(@RequestParam(required = false,defaultValue = "")String departmentId,
                                  @RequestParam(required = false,defaultValue = "0")int dateType,
                               @RequestParam(required = false,defaultValue = "")String startTime,
                               @RequestParam(required = false,defaultValue = "")String endTime) {
        Result result = new Result();
        if(dateType!=0&&"".equals(startTime)){
            switch (dateType){
                case 1://最近一个月
                    startTime=TimeUtil.getNowDetailedTime(1,1);
                    break;
                case 2://最近三个月
                    startTime=TimeUtil.getNowDetailedTime(1,3);
                    break;
                case 3://最近半年
                    startTime=TimeUtil.getNowDetailedTime(1,6);
                    break;
                case 4://最近1年
                    startTime=TimeUtil.getNowDetailedTime(2,1);
                    break;
            }
        }
        endTime="".equals(endTime)?TimeUtil.getNowTime():endTime;
        endTime=TimeUtil.getSpecifiedDayAfter(endTime);
        departmentId="0".equals(departmentId)?"":departmentId;
        List<CaseCount> list=caseCountService.selectCountByEnd(departmentId,startTime,endTime);
        result.setData(list);
        result.setCount(list.size());
        return result;
    }

}
